import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn } from 'typeorm'
import { OrderEntity } from '../../order/entities/order.entity'

@Entity('refund')
export class RefundEntity {
  @PrimaryGeneratedColumn()
  id: number

  // 关联订单（多对一：多个退款记录对应一个订单）
  @ManyToOne(() => OrderEntity, (order) => order.id, {
    onDelete: 'CASCADE', // 订单删除时，关联的退款记录也删除
  })

  @JoinColumn({ name: 'order_id' })
  order: OrderEntity

  @Column({ type: 'int', comment: '订单ID' })
  order_id: number

  @Column({ type: 'text', nullable: true, comment: '用户退款备注' })
  user_remark: string

  @Column({ type: 'text', nullable: true })
  merchant_remark?: string

  @Column({ type: 'tinyint', default: 1, comment: '退款状态：1待处理 2已同意 3已拒绝' })
  status: number

  @Column({ type: 'int' })
  user_id: number

  @Column({ type: 'tinyint', default: 0 })
  is_del?: number

  @Column({ default: Math.floor(Date.now() / 1000), comment: '申请时间' })
  apply_time: number

  @Column({ nullable: true, default: 0, comment: '操作时间' })
  operate_time?: number
}